home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
dylibload
/
LibrarySearchingLoad.c
next >
Wrap
C/C++ Source or Header
|
1992-04-16
|
6KB
|
218 lines
/* begincopyright
Copyright (c) 1988-1991 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* LibrarySearchingLoad.c
*
* Demers, January 17, 1991 4:59:28 pm PST
*/
#include "xr/BasicTypes.h"
#include "xr/IncrementalLoad.h"
#include "xr/IncrementalLoadPrivate.h"
#include "xr/CommandLine.h"
#include "xr/CommandLoop.h"
#include "xr/ThreadsMsg.h"
#include "xr/UIO.h"
#include "xr/libsearch.h"
typedef struct XR_PrintUndefinedDataRep {
bool pud_firstEntry;
XR_CLCallEnv pud_clce;
} *XR_PrintUndefinedData;
static bool
XR_LSLPrintUndefinedSymbol(se, clientData)
XR_ILSymEntry se;
XR_Pointer clientData;
{
# define pud ((XR_PrintUndefinedData)(clientData))
XR_CLCallEnv clce = pud->pud_clce;
if( pud->pud_firstEntry ) {
XR_CLErrorMsg "Undefined:\n");
pud->pud_firstEntry = FALSE;
}
XR_CLErrorMsg " %s", se->ilse_name);
if( se->ilse_ilfe != NIL ) {
XR_CLErrorMsg
" (referenced from %s)", se->ilse_ilfe->ilfe_fName);
}
XR_CLErrorMsg "\n");
return TRUE;
}
#undef pud
static bool
XR_LSLGetNextUndefinedSymbol(se, clientData)
XR_ILSymEntry se;
XR_Pointer clientData;
{
# define resP ((XR_ILSymEntry *)(clientData))
*resP = se;
return FALSE;
}
static void
XR_LibLoadCommandPatchSizeProc(ilfe, bytes)
XR_ILFileEntry ilfe;
unsigned bytes;
{
ilfe->ilfe_pBytes = bytes;
}
static
XR_CLPROC(XR_CLProc_librarySearchingLoad)
{
XR_ILError ile = NIL;
XR_ILError ile2;
XR_ILSymEntry nextUndefinedSymbol;
bool symFoundInLibrary;
XR_Fildes fd;
unsigned offset;
unsigned magic;
char *modulename;
char *cp;
int i;
void (*patchSizeProc)() = NIL;
long int patchBytes = 0;
ile = XR_LockIncrementalLoadState(TRUE);
if( ile != NIL ) {
XR_CLErrorMsg "%s: error %d: %s\n",
argv[0], ile->ile_code, ile->ile_msg);
return (-1);
}
for( i = 1; i < argc; i++ ) {
if( (argv[i][0] == '-') && (argv[i][1] == 'p') ) {
patchBytes = atoi(&(argv[i][2]));
if( patchBytes > 0 ) {
patchSizeProc = XR_LibLoadCommandPatchSizeProc;
} else {
if( patchBytes < 0 )
XR_CLLogMsg "bad flag %s ignored ... ", argv[i]);
patchSizeProc = NIL;
patchBytes = 0;
}
continue;
}
XR_CLLogMsg "loading %s ... ", argv[i]);
ile = XR_ILLoadFile(
/*fName*/ argv[i],
/*fOffset*/ 0,
/*fMagic*/ 0,
/*refProc*/ NIL,
/*refClientData*/ NIL,
/*defProc*/ NIL,
/*defClientData*/ NIL,
/*commonProc*/ NIL,
/*commonClientData*/ NIL,
/*patchSizeProc*/ patchSizeProc,
/*patchSizeClientData*/ patchBytes
);
if( ile != NIL ) {
XR_CLLogMsg "error %d: %s\n", ile->ile_code, ile->ile_msg);
break;
}
XR_CLLogMsg "ok\n");
}
for(;;) {
if( ile != NIL ) break;
ile = XR_CommitIncrementalLoad();
if( ile == NIL ) break;
nextUndefinedSymbol = NIL;
XR_ILEnumerateUndefinedSyms(
XR_LSLGetNextUndefinedSymbol,
((XR_Pointer)(&nextUndefinedSymbol)) );
if( nextUndefinedSymbol == NIL ) /* ile still not nil */ break;
if( (nextUndefinedSymbol->ilse_type & ILSE_TYPE) != ILSE_UNDF ) {
XR_ConsoleMsg("nextUndefinedSymbol botch name %s type 0x%x\n",
nextUndefinedSymbol->ilse_name, nextUndefinedSymbol->ilse_type );
break;
}
XR_CLLogMsg "searching for %s in library ... ",
nextUndefinedSymbol->ilse_name );
symFoundInLibrary = XR_lib_symfind( nextUndefinedSymbol->ilse_name,
&fd, &offset, &magic, &modulename );
if( !symFoundInLibrary ) {
XR_CLLogMsg "not found\n");
break;
}
for (cp = modulename; (*cp != 0) && (*cp != '('); cp++) {};
XR_CLLogMsg "found in %s\n", cp);
*cp = 0;
ile = XR_ILLoadFile(
/*fName*/ modulename,
/*fOffset*/ offset,
/*fMagic*/ 0,
/*refProc*/ NIL,
/*refClientData*/ NIL,
/*defProc*/ NIL,
/*defClientData*/ NIL,
/*commonProc*/ NIL,
/*commonClientData*/ NIL,
/*patchSizeProc*/ patchSizeProc,
/*patchSizeClientData*/ patchBytes
);
}
if( ile != NIL ) {
struct XR_PrintUndefinedDataRep pud;
pud.pud_firstEntry = TRUE;
pud.pud_clce = clce;
XR_ILEnumerateUndefinedSyms(
XR_LSLPrintUndefinedSymbol,
((XR_Pointer)(&pud)) );
(void) XR_AbortIncrementalLoad(NIL);
(void) XR_UnlockIncrementalLoadState();
XR_CLErrorMsg "%s: error %d: %s\n",
argv[0], ile->ile_code, ile->ile_msg );
if( i < argc ) XR_CLErrorMsg "\tfile: %s\n", argv[i]);
return (-1);
} else {
(void) XR_UnlockIncrementalLoadState();
return 1;
}
}
char *(cmdDescription[]) = {
(char *)XR_CLProc_librarySearchingLoad, NIL,
"[-ppatchbytes] filename ... -- load object files (with library search)",
"load", "load_files", "libload_files", NIL,
NIL
};
int
XR_run_LibrarySearchingLoad()
{
int regAns;
regAns = XR_CLUnsafeRegisterProcs(XR_globalCLProcsHandle, cmdDescription);
if( regAns < 0 ) {
XR_ConsoleMsg("run_LibrarySearchingLoad FAILURE %d\n", regAns);
return -1;
}
}